/**
 * related to listRowTemplate.ui
 * 
 * @Author : chenglm
 * @Timestamp : 2016-07-15
 */
var root=ui("$");
var nf = sm("do_Notification");
var homemakingUtil = require("url/homemaking");
var qqHttp = require("helper/http");
var helperOpen = require("helper/open");
var helperOrder = require("helper/order");
var do_Label_num = ui("do_Label_num");
var do_ALayout_order = ui("do_ALayout_order");
var do_ImageView_img = ui("do_ImageView_img");
var do_Label_title = ui("do_Label_title");
var do_Label_time = ui("do_Label_time");
var do_Label_orderStatus = ui("do_Label_orderStatus");
var do_Label_total = ui("do_Label_total");
var do_Button_doing = ui("do_Button_doing");
var do_Button_cancel = ui("do_Button_cancel");
var layoutBtn = ui("layoutBtn");
//设置数据绑定的映射关系
root.setMapping({
	"do_Label_num.text":"orderNo",
	"do_Label_num.tag":"orderType",
	"do_ImageView_img.source":"fullImg",
	"do_Label_title.text":"title",
	"do_Label_time.text":"strNewAt",
	"do_Label_orderStatus.tag":"orderStatus",
	"do_Label_total.text":"total",
	"do_Button_doing.tag":"payStatus",
	"do_Button_cancel.tag" : "deliveryStatus",
	"do_Label_10.text" :"buyerNick",
	"do_Label_orderStatus.text" : "orderStatusText",
	"layoutBtn.tag" : "index",
	"layoutBtn.visible" : "hasBtn",
	"do_Button_cancel.visible" : "showCancel",
	"do_Button_doing.visible" : "showDelivery"
});

root.on("dataRefreshed", function(){
	do_Label_total.text = "￥" + do_Label_total.text;
});

do_ALayout_order.on("touch", function(data){
	var orderNo = do_Label_num.text;
	helperOpen.open("source://view/homemaking/order/detail.ui", {orderNo:orderNo,index:layoutBtn.tag});
});

do_Button_cancel.on("touch", function(data){
	var orderNo = do_Label_num.text;
	nf.confirm("确定取消订单?", "", "确定", "我再想想", function(data, e) {
		if (data == 1) {
			if(do_Label_num.tag == 1){
				helperOrder.sellerCancel(orderNo);
			}
			do_Label_orderStatus.text = "卖家已取消";
			layoutBtn.visible = false;
		}
	});
});

do_Button_doing.on("touch", function(data){
	nf.confirm("确定完成服务?", "", "确定", "我再想想", function(data, e) {
		if (data == 1) {
			var orderNo = do_Label_num.text;
			qqHttp.post(homemakingUtil.url.order.completeService, {orderNo:orderNo}, function(data) {
				do_Label_orderStatus.text = "待买家确认";
				layoutBtn.visible = false;
			});
		}
	});
});

